<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>jsonp实现跨域</title>
  </head>
  <body>
    <button id="btn" onclick="getStudents()">获取学生数据</button>

    <script>
      function tets(data) {
        console.log('data', data);
      }
      function getStudents() {
        const script = document.createElement('script');
        script.src = 'http://localhost:3000/student?callback=tets';
        document.body.appendChild(script);
        script.onload = () => {
          script.remove();
        };
      }
      //   function throttle(fun, wait = 500) {
      //     let lastTime = 0;
      //     return function (...args) {
      //       let now = Date.now();
      //       if (now - lastTime > wait) {
      //         lastTime = now;
      //         fun.apply(this, args);
      //       }
      //     };
      //   }

      //   const btn = document.querySelector('#btn');
      //   btn.addEventListener('click', throttle(getStudents, 500));
    </script>

    <!--   <script>
      function callback(data) {
        console.log('data', data);
      }
    </script>
    <script type="text/javascript" src="http://localhost:3000/student"></script> -->
  </body>
</html>
